<?php
include('simple_html_dom.php');
?>
<div id="wrapper">
    <div id="main_content">
        <div class="listcats">
            <ul>
                <?php foreach($categories as $category){?>
                <?php $news = $category->news; ?>
                 <?php if (sizeof($news) > 0){ ?>
                <li>
                    <div class = "catstitle">
                        <?php echo CHtml::link($category->category_name, array('CategoryDetail/view','id' =>$category->category_id )) ?>
                    </div>
                    <div class="listnews">
                        
                       
                        <?php $i = 0; ?>
                        <?php foreach($news as $new){ ?>
                            <?php if($i == 0){ ?>
                                 <span class="first_news">
                                    <a href="index.php?r=detail/view&id=<?php echo $new -> news_id; ?>">
                                        <?php
                                        $images = str_get_html(htmlspecialchars_decode($new -> news_description));
                                        $image = $images->find('img');
                                        echo CHtml::link('<img src="'.$image[0]->src.'"></img>', array('detail/view','id' =>$new -> news_id))
                                        ?>
                                    </a>
                                     <br/>
                                     <div><?php echo CHtml::link($new->news_title, array('detail/view','id' =>$new -> news_id)) ?></div>
                                     <p><?php echo substr(strip_tags(htmlspecialchars_decode($new->news_description)),0,280).'...'; ?></p>
                                     <br/>
                                 </span>
                            <?php $i++;} else{?>
                            <span class="other_news">
                                <?php echo CHtml::link($new->news_title, array('detail/view','id' =>$new -> news_id)) ?>
                                <br/>
                            </span>
                            <?php } ?>
                        <?php } ?>
     
                    </div>
                </li>
                <?php } ?>    
            <?php }?>
            </ul>
        </div>
        
        <div class="fistArt3">
            <ul>
                <?php foreach ($listnews as $news) { ?>
                    <li>
                            
                        <div class="news_title_big">
                              <?php echo CHtml::link($news->news_title, array('detail/view','id' => $news -> news_id)); ?>
                           
                        </div>
                        <div class="news_post_time">
                            <?php echo $news->news_created_at ?>
                        </div>
                        <div class="news_image_big">
                            <a href="index.php?r=detail/view&id=<?php echo $news -> news_id; ?>">
                                <?php
                                $images = str_get_html(htmlspecialchars_decode($news -> news_description));
                                $image = $images->find('img');
                                echo '<img src="'.$image[0]->src.'"></img>';
                                ?>
                                
                           </a></a>     
                        </div>
                      
                        <div class="news_content_big">
                            <?php echo strip_tags(htmlspecialchars_decode($news -> news_description)); ?>
                        </div>
                      
                    </li>
                    <?php } ?>
            </ul>
        </div>
        
    </div>
    <!--
    <div id="ad_center">
        <h2 style="text-align: center;color:#555;">Ads 1000x100</h2>
    </div>
    -->
 	<div id="ads_content">
        <div id="hot_video">
            <h2>Quảng cáo</h2>
            <ul>
            	<?php foreach($ads as $ad){ ?>
			                <li>
				<div class="ads_title">
					<a href="<?php echo $ad->ads_url; ?>"><?php echo $ad -> ads_title; ?></a>
				</div>
				<div class="ads_website">
					<a href="<?php echo $ad-> ads_url; ?>"><?php echo $ad -> ads_website; ?></a>
				</div>
				<div class="ads_content">
					<a href="<?php echo $ad -> ads_url; ?>">
						<?php if($ad->ads_image != null){?>
							<img src="<?php echo $ad -> ads_image; ?>" /> 
						<?php }else{ ?>
							<img src="images/default.jpg" /> 
						<?php } ?>
					</a>
					<div class="ads_desc">
						<?php echo $ad-> ads_desc; ?>
					</div>
				</div>
			</li>
			<?php } ?>
			
            </ul>
        </div>
    </div>

    <!--  end ads content -->
</div>